package com.yunhe.abnormal.controller.base;

import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.base.AlarmNotifyTypeDTO;
import com.yunhe.abnormal.service.base.AlarmNotifyTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 异常通知类型Controller
 * @author liuronglei
 */
@Api(value = "alarmNotifyType", description = "异常通知类型", tags = {"Base_AlarmNotifyType"})
@RestController
@RequestMapping("/alarmNotifyTypes")
public class AlarmNotifyTypeController {
    @Autowired
    private AlarmNotifyTypeService alarmNotifyTypeService;

    /**
     * 根据价格类型ID获得价格类型
     * @param id 价格类型ID
     */
    @ApiOperation("根据价格类型ID获得价格类型")
    @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "long", paramType = "path")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public ResponseEntity<ResultObject> get(@PathVariable("id") Long id) {
        AlarmNotifyTypeDTO alarmNotifyType = alarmNotifyTypeService.findById(id);
        return new ResponseEntity<>(new ResultObject<>(alarmNotifyType), HttpStatus.OK);
    }

    /**
     * 根据name获得异常通知类型
     * @param name 异常通知类型name
     */
    @ApiOperation("根据name获得异常通知类型")
    @ApiImplicitParam(name = "name", value = "异常通知类型name", required = true, dataType = "string", paramType = "query")
    @RequestMapping(value = "/byName", method = RequestMethod.GET)
    public ResponseEntity<ResultObject> get(@RequestParam("name") String name) {
        AlarmNotifyTypeDTO alarmNotifyType = alarmNotifyTypeService.findByName(name);
        return new ResponseEntity<>(new ResultObject<>(alarmNotifyType), HttpStatus.OK);
    }

    /**
     * 根据条件获得异常通知类型列表
     */
    @ApiOperation("根据条件获得异常通知类型列表")
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity<ResultObject> search() {
        Iterable<AlarmNotifyTypeDTO> results = alarmNotifyTypeService.findAll();
        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
    }
}
